package com.zhangfei.stream;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * limit作用：断流，使其元素不超过给定数量。保留集合前面的数据。
 */
public class LimitTest {
    public static void main(String[] args) {
        //初始化学生数据并转成list
        List<Student> students = Arrays.asList(
                new Student(1, "张三", 25),
                new Student(1, "李四", 32),
                new Student(1, "王五", 40),
                new Student(1, "赵六", 29));
        limitStuden(students);
    }

    public static void limitStuden(List<Student> students) {
        List<Student> studentList = students.stream()
                .limit(3)
                .collect(Collectors.toList());
        System.out.println(studentList);
    }
}
